$(function () {
    var datagrid=$("#att_datagrid");
    datagrid.datagrid({
        fitColumns: true,
        fit: true,
        toolbar: '#att_toolbar',
        url: '/duty/list.do',
        pagination: true,
        striped: true,
        rownumbers: true,
        singleSelect: true,
        columns: [[
            {title: '日期', field: 'date',align:'center', width:'100'},
            {title: '员工姓名', field: 'employee' ,align:'center', width:'100',formatter: function (value, row, index) {
                    return value?value.username:"";
                }},
            {title: '部门', field: 'department' ,align:'center', width:'100',formatter: function (value, row, index) {
                    return value?value.name:"";
                }},
            {title: '上班时间', field: 'signOn',align:'center', width:'100'},
            {title: '下班时间', field: 'signOff',align:'center', width:'100'},
            {title: '考勤状态', field: 'state',align:'center', width:'100',formatter: function (value, row, index) {
                    return value ? "<font color='green'>正常</font>" : "<font color='red'>异常</font>"
                }}
        ]],
    })

    var methodObj = {
        //刷新按钮
        reload: function () {
            datagrid.datagrid("reload");
        },
        query: function () {
            var beginDate=$("#beginDate").textbox("getValue");
            var endDate=$("#endDate").textbox("getValue");
            var keyword=$("#keyword").textbox("getValue");
            var qoDept=$("#qoDept").textbox("getValue");
            qoDept = qoDept*0===0?qoDept:-1;
            $("#att_datagrid").datagrid('load', {
                "keyword": keyword,
                "deptId":qoDept,
                "beginDate":beginDate,
                "endDate":endDate
            });
        }
    }

    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        methodObj[cmd]();
    })

})

